/**
 * @param {string} s
 * @return {boolean}
 */

var isValid = function (s) {
    let map = new Map([
        ["(", ")"],
        ["[", "]"],
        ["{", "}"]
    ])
    let len = s.length
    let stack = []
    for (let i = 0; i < len; i++) {
        // 如果为左括号 则推入
        if (map.has(s[i])) {
            stack.push(map.get(s[i]))
        } 
        // 否则 就出栈对比
        else {
            let val = stack.pop()
            if (val !== s[i]) {
                return false
            }
        }
    }
    return !stack.length
};